﻿using EnvDTE;

namespace Behaviorize.CodeGenerator.VsProject
{
	public class ProjectItemService : IProjectItemService
	{
		public ProjectItem GetProjectItem(BaseCodeGeneratorWithSite baseCodeGeneratorWithSite)
		{
			return baseCodeGeneratorWithSite.GetProjectItem();
		}

		public ProjectItem GetSubItem(ProjectItem projectItem, string subItemFilename)
		{
			foreach (object item in projectItem.ProjectItems)
			{
				var subItem = (ProjectItem)item;
				for (short i = 0; i < subItem.FileCount; i++)
				{
					if (subItem.FileNames[i] == subItemFilename) return subItem;
				}
			}

			return null;
		}

		public string GetNamespace(BaseCodeGenerator baseCodeGeneratorWithSite)
		{
			return baseCodeGeneratorWithSite.FileNameSpace;
		}
	}
}